package org.summerframework.component.security.core.interceptor;

import org.summerframework.component.security.LoginData;
import org.summerframework.component.security.context.RequestContext;
import org.summerframework.component.security.context.RequestContextFactory;
import org.summerframework.core.interceptor.AbstractHandlerInterceptorAdapter;
import org.springframework.beans.factory.annotation.Value;

import java.io.IOException;

/**
 * 拦截器
 * <p>
 * 抽象出获取class、method上的Annotation
 * <p>
 * 获取顺序  method  >  class
 *
 * @author 石超
 * @version v1.0.0
 */
public abstract class AbstractContextHandlerInterceptorAdapter extends AbstractHandlerInterceptorAdapter {
    @Value("${spring.exception.isHtmlRequired}")
    private Boolean isHtmlRequired = false;

    /**
     * 重定向url
     */
    protected void redirect(String url) throws IOException {
        getContext().getResponse().sendRedirect(url);
    }

    protected <T> RequestContext<LoginData<T>> getContext() {
        return RequestContextFactory.getCurrentContext();
    }

}
